import org.dom4j.*;
import org.dom4j.dom.DOMDocument;
import org.dom4j.dom.DOMElement;
import org.dom4j.io.XMLWriter;
import org.xml.sax.SAXException;

import java.io.IOException;

/**
 * @author Lance Li
 * @date 7/9/2018 4:56 PM
 * @desc
 */
public class Main {

    public static void main(String[] args) throws DocumentException, SAXException, IOException {
//        SAXReader reader = new SAXReader();
//        Document document = reader.read(new File("books.xml"));
        Element root = new DOMElement("books");
        Document doc = new DOMDocument();
        doc.setRootElement(root);
        for(int i = 0; i < 10; i++){
            Element element = new DOMElement("books");
            Element idElement = new DOMElement("id");
            idElement.setText(i+"");
            Element nameElement = new DOMElement("name");
            nameElement.setText("name" + i);
            element.add(idElement);
            element.add(nameElement);
            root.add(element);
        }

        XMLWriter xmlWriter = new XMLWriter(System.out);
        xmlWriter.write(doc);

    }
}
